package com.example.smartcity_40

import android.content.IntentFilter
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.smartcity_40.Fragment.*
import com.example.smartcity_40.databinding.ActivityMainBinding
import com.example.smartcity_40.home.Jump
import com.example.smartcity_40.tool.viewBinding

class MainActivity : AppCompatActivity() {
    private  lateinit var  jump :Jump
      lateinit var  filter :IntentFilter
    private val vb by viewBinding(ActivityMainBinding::inflate)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(vb.root)

        jump = Jump(vb.mainNav)
        filter = IntentFilter("jump")
        filter.addAction("jump")
        registerReceiver(jump,filter)

        vb.mainNav.setOnNavigationItemSelectedListener {
            val fragment = when(it.itemId) {
                R.id.nav_home -> Homeragment()
                R.id.nav_service -> ServiceFragment()
                R.id.nav_help -> HelpFragment()
                R.id.nav_news -> NewsFragment()
                R.id.nav_news -> NewsFragment()
                R.id.nav_me -> MeFragment()
                else -> Homeragment()
            }
            supportFragmentManager.beginTransaction().replace(R.id.main_container,fragment).commit()
            true
        }
        supportFragmentManager.beginTransaction().replace(R.id.main_container,Homeragment()).commit()
    }
}